<template>
	<view class="deep">
		<view class="pl-3 mt-3 bg-white border-bottom border-top" >
			<view class="d-flex j-sb pr-2 py-3" @click="toggle(item,index)" v-for="(item,index) in toggleList" :key="index">
				<view class=""><text class="">{{item.name}}</text><text class="text-success ml-2">校验完成</text></view>
				<view class="d-flex j-center a-center">
					<u-icon v-show="index==count" name="checkmark" color="#ff0000" size="35"></u-icon>
				</view>
			</view>
		</view>
		<view class="m-2 ">
			<button type="warn" @click="confrim_toggle">确认切换</button>
		</view>
	</view>
</template>

<script>
	import {mapMutations,mapState} from 'vuex';
	export default {
		data() {
			return {
				toggleList:[
					{id:0,name:"默认"},
					{id:1,name:"世联DEMO"}
				],
				count:0,
				name:"",
			}
		},
		onLoad() {
			if(uni.getStorageSync("toggle_default")){
				this.count=0
			}else if(uni.getStorageSync("toggle_demo")){
				this.count=1
			}
		},
		methods: {
			...mapMutations(['webUrl']),
			// 选中
			toggle(item,index){
				this.name=item.name
				this.count=index
				// if(item.name=='默认'){
				// 	console.log(item)
				// }else if(item.name=='世联DEMO'){
				// 	uni.setStorageSync("toggle_demo",item)
				// 	console.log(this.name)
				// }
			},
			// 确认切换
			confrim_toggle(){
				
				if(this.name=="默认"){
					uni.setStorageSync("user",this.localConfig.web_Url)
					uni.navigateBack({
						delta:1
					})
					this.webUrl(this.localConfig.web_Url)
					uni.setStorageSync("toggle_default",this.name)
					
					uni.removeStorageSync('toggle_demo');
				}else if(this.name=="世联DEMO"){
					uni.setStorageSync("user_demo",this.localConfig.demo_Url)
					uni.navigateBack({
						delta:1
					})
					uni.setStorageSync("toggle_demo",this.name)
					uni.removeStorageSync('toggle_default');
					this.webUrl(this.localConfig.demo_Url)
				}else{
					uni.setStorageSync("user",this.localConfig.web_Url)
					uni.navigateBack({
						delta:1
					})
					this.webUrl(this.localConfig.web_Url)
					uni.setStorageSync("toggle_default",this.name)
					uni.removeStorageSync('toggle_demo');
				}
			}
		}
	}
</script>

<style>
	.deep  /deep/ button{
		padding: 10upx 0;
		font-size: 28upx;
	}
</style>
